package main;

import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.Map;
//import java.util.Properties;

import dataStore.FtpServerApi;
import dataStore.FtpServerApiInterface;
import dataStruct.FileInfo;
import dataStruct.WordcountFileInfo;

//import tool.GetProper;

public final class CreateRegistry {
	public static void createRegistry(Map<String, FileInfo> fileMd5FileContentMap,
			Map<String, WordcountFileInfo> wordcountFileMd5Map) 
			throws AlreadyBoundException, RemoteException, InterruptedException, SQLException, NotBoundException {
		
//		Properties masterProper = GetProper.get_properties("conf/config.ini");

		int port = 3001;
		Registry registryFtp = 	LocateRegistry.createRegistry(port);
		/**********ftpServerApi  registry**********/
		FtpServerApi	 ftpServerApi = new FtpServerApi(
				 fileMd5FileContentMap, 
				 wordcountFileMd5Map
				);
		FtpServerApiInterface ftpServerApiInterface = (FtpServerApiInterface) UnicastRemoteObject.exportObject( ftpServerApi, 0);
		// Bind the remote object's stub in the registry
		registryFtp.rebind("ftpServerApi", ftpServerApiInterface);
		System.out.println("ftpServerApi has started"); // 父进程死亡，子进程变为孤儿进程
	}
}
